package com.sum.tea.rongrui

import android.app.TabActivity
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.Window
import com.example.lib_rongrui.RrReader
import com.sum.tea.R
import com.sum.tea.contants.AppConstants

class RMainActivity : TabActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.activity_rongrui_main)
        val intent0 = Intent(this, ScanModeActivity::class.java)
        val intent1 = Intent(this, ReadWriteActivity::class.java)
        val intent2 = Intent(this, ScanViewActivity::class.java)
        val intent3 = Intent(this, MaskActivity::class.java)
        val intent4 = Intent(this, FindingActivity::class.java)

        val tabSpec0 = tabHost.newTabSpec(getString(R.string.tab_scan)).setIndicator(getString(R.string.tab_scan)).setContent(intent0)
        val tabSpec1 = tabHost.newTabSpec(getString(R.string.tab_rw)).setIndicator(getString(R.string.tab_rw)).setContent(intent1)
        val tabSpec2 = tabHost.newTabSpec(getString(R.string.tab_param)).setIndicator(getString(R.string.tab_param)).setContent(intent2)
        val tabSpec3 = tabHost.newTabSpec(getString(R.string.tab_mask)).setIndicator(getString(R.string.tab_mask)).setContent(intent3)
        val tabSpec4 = tabHost.newTabSpec(getString(R.string.finding)).setIndicator(getString(R.string.finding)).setContent(intent4)

        tabHost.addTab(tabSpec0)
        tabHost.addTab(tabSpec4)
        tabHost.addTab(tabSpec1)
        tabHost.addTab(tabSpec3)
        tabHost.addTab(tabSpec2)
        tabHost.currentTab = 0
        createOberver()
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        return true
    }

    private fun createOberver() {
        AppConstants.TabState.observeForever{
            tabHost.currentTab = it
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        RrReader.rrlib.DisConnect()
    }

}
